package com.gibs.peixunapi.controller;

import com.gibs.peixunapi.VO.CourseInfoVO;
import com.gibs.peixunapi.model.Course;
import com.gibs.peixunapi.result.Result;
import com.gibs.peixunapi.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.transaction.Transactional;
import javax.validation.Valid;

/**
 * 功能：课程模块
 * 项目：装配式培训平台
 * 日期：2020-08-20
 * 作者：梁嘉伟
 */

@Slf4j
@Api(tags = "课程模块API")
@Transactional(rollbackOn = Exception.class)
@RestController
@RequestMapping("/Courses")
public class Courses extends Application {

    @Autowired
    private CourseService courseService;

    //TODO
    //TODO 新增文档课程
    //TODO 新增视频课程
    //TODO 获取课程列表
    //TODO 获取课程信息
    //TODO 课程审核
    @ApiOperation(value = "新增课程基本信息")
    @PostMapping("/create")
    public Result create(@RequestBody CourseInfoVO courseInfoVO) {
        return courseService.create(courseInfoVO);
    }

    @Transactional
    @PostMapping("/save")
    public Result save(@Valid Course object, BindingResult bindingResult) {

        Result errorList = getResult(bindingResult);
        if (errorList != null) {
            return errorList;
        }
        return courseService.save(object);

    }

    @PostMapping("/delete")
    public Result delete(Integer id) {


        return courseService.delete(id);
    }

    @GetMapping("/get")
    public Result get(Integer id) {
        return courseService.get(id);
    }

    @GetMapping("/getList")
    public Result getList(String key) {
        return courseService.getList(key);
    }

    @GetMapping("/getListPage")
    public Result getListPage(String key, Integer current, Integer limit) {

        return courseService.getListPage(key, current, limit);

    }

    @GetMapping("/getOptions")
    public Result getOptions(String key) {
        return courseService.getOptions(key);
    }


}

